
const Controller = require('../../core/Controller');
const query = require('../../core/db');


class couponController extends Controller {
  constructor() {
    super();
  }
  async getMessageList(ctx) {
    let sql = 'select * from message where 1=1';
    let values = [];
    ctx.response.body = await query(sql, values).then( results => { return results; });
  }

  async delMessage(ctx) {
    const { m_id = '' } = ctx.request.body || ctx.request.query;

    let values = [m_id];
    let sql = ` DELETE FROM message WHERE m_id=?;`;
    try {
      let res = await query(sql, values).then( results => { return results; });
      console.log('res', res);
      ctx.response.body = {
        succ: true
      };
    } catch (e) {
      console.log('e', e);
      ctx.response.body = {
        succ: false
      };
    }
  }

  async addMessage(ctx) {
    const { m_content } = ctx.request.body || ctx.request.query;

    let values = [m_content, new Date()];
    //console.log('values', values);
    let sql = `INSERT INTO message (m_content,m_time) VALUES (?,?)`;
    console.log('values', values);
    try {
      let res = await query(sql, values).then( results => { return results; });
      //console.log('coupon', coupon);
      ctx.response.body = {
        succ: true
      };
    } catch (e) {
      console.log('e', e);
      ctx.response.body = {
        succ: false
      };
    }
  }

}

module.exports = new couponController;
